$(function () {
    $.validator.setDefaults({
        errorElement: 'span',
        errorClass: 'error',
        errorPlacement: function (error, element) {
            error.appendTo(element.parent().next()).before('<span class=span></span>');
        },
        unhighlight: function (element) {
            $('small').addClass('small');
        }
    })
    $('form').validate({
        debug: true,
        rules: {
            userName: {
                required: true,
                minlength: 4,
                maxlength: 20
            },
            userpsw: {
                required: true,
                minlength: 6,
                maxlength: 20
            },
            psw: {
                required: true,
                equalTo: '#userpsw'//equalTo 内容一致
            },
            phone: {
                required: true,
            },
            messages: {
                userName: {
                    required: '请输入用户名',
                    minlength: '长度只能在4-20个字符之间'
                },
                userpsw: {
                    required: '请输入密码',
                    minlength: '长度只能在6-20个字符之间',
                    maxlength: '至多输入10个字符'
                },
                psw: {
                    required: '请确认密码',
                    equalTo: '两次密码输入不一致'
                },
            }
        }

    })
    $('form').submit(function (e) {
        e.preventDefault();
        var password = $(':password').map(function () {
            return $(this).val();
        });
        $.post(this.action, $(this).serialize(), (data) => {
            if (data.code == 'success') {
                location.href = '/login.html';
            }
        })
    })

})